package com.youhome.wechat.controller;

import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.youhome.common.config.WeChatConfig;
import com.youhome.common.exception.CustomException;
import com.youhome.common.response.Result;
import com.youhome.common.response.ResultCode;
import com.youhome.service.model.BUser;
import com.youhome.service.model.UserLoginInfo;
import com.youhome.service.model.WXSession;
import com.youhome.service.service.BUserService;
import com.youhome.service.service.TokenService;
import com.youhome.service.service.WXService;
import com.youhome.utils.HttpClientUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;

/**
 * Created by chen365 on 2018/12/06.
 */
@RestController
@RequestMapping(value = "/wx")
@Api(tags = "微信")
@Slf4j
public class WXController {
    @Autowired
    private WXService wxService;

    @ApiOperation(value = "微信授权", notes = "微信授权", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiImplicitParam(dataType = "String", name = "code", value = "code", required = true, paramType = "query")
    @PostMapping(value = "/login")
    public Object login(String code) throws CustomException {
        return new Result<>(ResultCode.SUCCESS, wxService.login(code));
    }
}
